/*
 * IndeterminateProgressDialog.java
 *
 *  created: 18.11.2011
 *  charset: UTF-8
 *  license: MIT (X11) (See LICENSE file for full license)
 */
package cz.mp.k3bg.gui.component;

import static cz.mp.k3bg.TextSource.getLocText;
import java.awt.Dialog.ModalityType;
import java.awt.Dimension;
import java.awt.Window;
import javax.swing.JDialog;
import javax.swing.JProgressBar;
import javax.swing.WindowConstants;
import net.miginfocom.swing.MigLayout;

/**
 * Dialog, který pouze zobrazuje nekonečný progress bar, pokud ho
 * někdo nezavře metodou {@linkplain #closeDialog()}.
 *
 * @author Martin Pokorný
 * @version 0.1
 */
public class IndeterminateProgressDialog extends JDialog {

    private Window owner;

    private JProgressBar progressBar = new JProgressBar();

    /** */
    public IndeterminateProgressDialog(Window owner) {
        super(owner, ModalityType.APPLICATION_MODAL);
        this.owner = owner;
        initComponents();
        initLayout();
        initDialog();
    }

    /** */
    private void initComponents() {
        progressBar.setIndeterminate(true);
    }

    /** */
    private void initLayout() {
        this.setLayout(new MigLayout("wrap",
                "para[fill,grow]para",
                "para[]para"));
        this.add(progressBar);
    }

    /** */
    private void initDialog() {
        setTitle(getLocText("gui.bookfiles.import.in_progress.title"));

        pack();
        setMinimumSize(new Dimension(300, getHeight()));
        setSize(getMinimumSize());

        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    }

    /** */
    public void showDialog() {
        setLocationRelativeTo(owner);
        setVisible(true);
    }

    public void closeDialog() {
        setVisible(false);
//        dispose();    // ne!
//        owner.requestFocus();
    }

}   // IndeterminateProgressDialog
